﻿<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<%
	String context = request.getContextPath();
	
	String advanceQueryExpression = (String)request.getParameter("advanceQueryExpression");
	String date = (String)request.getParameter("date");
	String position = (String)request.getParameter("position");
	String pageSize = (String)request.getParameter("pageSize");
	
	if(advanceQueryExpression == null) advanceQueryExpression = "";
	//else advanceQueryExpression = new String(advanceQueryExpression.getBytes("ISO-8859-1"),"utf-8");
	//System.out.println(advanceQueryExpression);
	if(date == null) date = "";
	if(position == null) position = "";
	if(pageSize == null) pageSize = "";
	
	String method = request.getParameter("method");
	if(method == null) method = "doSearch";
	String  action = context + SearchConfigUtil.getSearchUrl() + "?action=" + method;
%>



<%@page import="component.fulltextsearch.util.SearchConfigUtil"%>
<%@page import="component.fulltextsearch.constant.SearchConstant"%><HTML>

<HEAD>
<TITLE>Gever 高级搜索</TITLE>
<META http-equiv=content-type content="text/html; charset=utf-8">

<link href="<%=(context + SearchConfigUtil.getAdvanceCss())%>" rel="stylesheet" type="text/css">

<script type="text/javascript" src="<%=(context + SearchConfigUtil.getSearchPath())%>/js/luceneQueryConstructor.js"></script>
<script type="text/javascript" src="<%=(context + SearchConfigUtil.getSearchPath())%>/js/luceneQueryValidator.js"></script>
<script type="text/javascript" src="<%=(context + SearchConfigUtil.getSearchPath())%>/js/DateUtil.js"></script>
       
</HEAD>


<BODY text=#000000 vLink=#551a8b aLink=#ff0000 link=#0000cc bgColor=#ffffff>
<FONT face=arial,sans-serif>

<FORM action="<%=action %>" method="post">

<table width=99% border=0 cellpadding=0 cellspacing=2>
	<tr>
		<td rowspan=2 width=1% nowrap="nowrap">
			<a id="logo" href="<%=(context + SearchConfigUtil.getSearchPath())%>/simpleSearch.jsp" title="Gever 主页">
				<IMG src="<%=(context + SearchConfigUtil.getSearchPath())%>/image/logo.jpg" border="0" >Gever</IMG>
			</a>
		</td>
		<td>&nbsp;</td>
		<td rowspan=2>
		<table cellspacing=0 cellpadding=0 border=0 width=100%>
			<tr>
				<td bgcolor=#3366cc><img width=1 height=1 alt=""></td>
			</tr>
		</table>
		<table cellspacing=0 cellpadding=0 border=0 width=100%>
			<tr>
				<td nowrap bgcolor=#d5ddf3><font face=arial,sans-serif
					color=#000000 size=+1><b>&nbsp;高级搜索</b></font></td>
				<td align=right nowrap bgcolor=#d5ddf3><font
					face=arial,sans-serif size=-1>
					<a href="<%=(context + SearchConfigUtil.getSearchPath())%>/help.jsp">搜索帮助</a> 
					<!-- | <a href="http://www.google.cn/intl/zh-CN/about.html">Gever 大全</a>&nbsp;-->
				</font></td>
			</tr>
		</table>
		<img width=1 height=8 alt='' src=""></td>
	</tr>
</table>

<TABLE cellSpacing=0 cellPadding=3 width="99%" border=0>
	<TBODY>
		<TR bgColor=#cbdced>
			<TD>
			<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
				<TBODY>
					<TR bgColor=#cbdced>
						<TD>
						<TABLE cellSpacing=0 cellPadding=2 width="100%">
							<TBODY>
								<TR>
									<TD vAlign=top width="15%">
									<FONT size=-1><BR><B>搜索结果</B></FONT>
									</TD>
									<TD width="85%">
									<TABLE cellSpacing=0 cellPadding=2 width="100%">
										<TBODY>
											<TR>
												<input name="noField-andModifier" value="+|0" type="hidden">
												<TD><FONT size=-1>包含<B>全部</B>字词</FONT></TD>
												<TD><INPUT size=25 value="" name="noField-and"
													id="noField-and">
												<TD vAlign=top rowSpan=4><FONT size=-1><INPUT
													type=hidden value=zh-CN name=hl><INPUT type=hidden
													value=1 name=newwindow><SELECT name=pageSize>
													<OPTION value=10 selected>10 项结果
													<OPTION value=20>20 项结果
													<OPTION value=30>30 项结果
													<OPTION value=50>50 项结果
													<OPTION value=100>100 项结果</OPTION>
												</SELECT> <INPUT type="button" onclick="doSearch()" value="搜索" name=btnG></FONT></TD>
											</TR>
											<TR>
												<input name="noField-orModifier" value=" |+" type="hidden">
												<TD noWrap><FONT size=-1>包含<B>至少一个</B>字词</FONT></TD>
												<TD><INPUT size=25 name="noField-or"></TD>
											</TR>
											<TR>
												<input name="noField-notModifier" value="-|0" type="hidden">
												<TD noWrap><FONT size=-1><B>不包括</B>字词</FONT></TD>
												<TD><INPUT size=25 name="noField-not"></TD>
											</TR>
										</TBODY>
									</TABLE>
									</TD>
								</TR>
							</TBODY>
						</TABLE>
						</TD>
					</TR>

					<TR bgColor=#ffffff>
						<TD>
						<TABLE cellSpacing=0 cellPadding=2 width="100%">
							<TBODY>
								<TR>
									<TD width="15%"><FONT size=-1><B>日期</B></FONT></TD>
									<TD noWrap width="40%"><FONT size=-1>返回在下列时间段内首次查看的内容
									</FONT></TD>
									<TD><FONT size=-1><SELECT name="date">
										<OPTION value="" selected>任何时间</OPTION>
										<OPTION value=d>过去一天内</OPTION>
										<OPTION value=w>过去一周内</OPTION>
										<OPTION value=m>过去一个月内</OPTION>
										<OPTION value=y>过去一年内</OPTION>
									</SELECT></FONT></TD>
								</TR>
							</TBODY>
						</TABLE>
						</TD>
					<TR>
						<TD>
						<TABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
							<TBODY>
								<TR bgColor=#ffffff>
									<TD width="15%"><FONT size=-1><B>字词位置</B></FONT></TD>
									<TD noWrap width="40%"><FONT size=-1>查询字词位于</FONT></TD>
									<TD>
									<FONT size=-1>
									<SELECT name="position">
										<OPTION value="" selected>任何地方</OPTION>
										<%
										String[] searchFieldArr = SearchConstant.SEARCHER_FIELD_NAMES;
										for(int i = 0;i<searchFieldArr.length;i++){
										%>
										<OPTION value="<%=searchFieldArr[i]%>"><%=SearchConstant.searchNameMap.get(searchFieldArr[i])%></OPTION>
										<%}%>
									</SELECT>
									</FONT>
									</TD>
								</TR>							
							</TBODY>
						</TABLE>
						</TD>
					</TR>
				</TBODY>
			</TABLE>
			</TD>
		</TR>
	</TBODY>
</TABLE>

<input type="hidden" name="advanceQueryExpression" id="advanceQueryExpression" />
<input type="hidden" name="query" />
<input type="hidden" id="noField-and-query" name="noField-and-query" />
<input type="hidden" id="noField-or-query" name="noField-or-query" />
<input type="hidden" id="noField-not-query" name="noField-not-query" />

<!--  
<table>
<tr><th><p>Current Query:</th><td><pre id="curQuery"></pre><pre id="curQueryValid"></pre></td></tr>
</table>
<br>
<input type="button" name="Update" value="Update Query" onClick="doSubmitForm(document.forms[0]); document.getElementById('curQuery').innerHTML = this.form.query.value" />
<input type="button" name="Validate" value="Validate" onClick="doCheckLuceneQuery(document.forms[0].query); getElementById('curQueryValid').innerHTML = 'Query is valid'" /> 
-->

<!--  
<br>
<hr>
<font color="red" size="3">
说明：<br>
1.允许输入的字符有 a-z A-Z 0-9.  _ + - : () \" & * ? | ! {} [ ] ^ ~ \\ @ = # % $ ' / <br>
2.通配符（ * ）之前必须至少有一个字符 <br>
3.查询包含特殊字符＆的格式必须是：字词＆字词 <br>
4.在插入( ^ )字符必须前面是字符和后面是数字 <br>
5.波形符( ~ )字符必须前面是字符和后面是数字(该验证有问题) <br>
6.查询包含特殊字符！的格式必须是：字词 ！字词 <br>
7.问号（ ？ ）之前必须至少有一个字母或数字(验证有问题) <br>
8.括号内必须至少包含一个字符 <br>
9.' + '和' - '之后必须至少有一个字符 <br>
10.查询包含 和/或/不是 必须的格式：字词 和|或|不|和 不字词 <br>
11.引号内必须包含至少一个字符 <br>
12.属性声明( ： )之前必须至少有一个字母或数字，随后至少有一个字母或数字 <br>
</font>
-->

</FORM>
</FONT>
</BODY>
</HTML>

<script>

function initSelect(selectName,value){
	var selectObj = document.getElementsByName(selectName)[0];
	var len = selectObj.options.length;
	for(i = 0;i<len;i++){
		var item = selectObj.options.item(i);
		if(item.value == value){
			item.selected = true;
			return;
		}
	}
}

initSelect("pageSize","<%=pageSize%>");
initSelect("date","<%=date%>");
initSelect("position","<%=position%>");

var advanceQueryExpression = "<%=advanceQueryExpression%>";
var arr = advanceQueryExpression.split(",");
document.getElementsByName("noField-and")[0].value = arr[0];
document.getElementsByName("noField-or")[0].value = arr[1];
document.getElementsByName("noField-not")[0].value = arr[2];

var method = "<%=method%>";
function doSearch(){
	var form = document.forms[0];
	
	var query = doMakeQuery(form.query,false);//第二个参数为是否进行调试:alert
	
	var noFieldAndValue = document.getElementById("noField-and-query").value;
	var noFieldOrValue = document.getElementById("noField-or-query").value;
	var noFieldNotValue = document.getElementById("noField-not-query").value;
	//alert("noFieldAndValue = " + noFieldAndValue + ",noFieldOrValue = " + noFieldOrValue + ",noFieldNotValue = " + noFieldNotValue);
	
	var isValAnd = doCheckLuceneQueryValue(noFieldAndValue.substring(1).trim(),"\“包含全部字词\”的输入框输入格式不对");
	if(!isValAnd) return false;
	
	var isValOr = doCheckLuceneQueryValue(noFieldOrValue.trim(),"\“包含至少一个字词\”的输入框输入格式不对");
	if(!isValOr) return false;
	
	var isValNot = doCheckLuceneQueryValue(noFieldNotValue.substring(1).trim(),"\”不包括字词\“的输入框输入格式不对");
	if(!isValNot) return false;
	
	//alert(isValAnd==true && isValOr==true && isValNot==true);
	
	//var isVal = doCheckLuceneQuery(query);
	//alert(isVal);
	/*
	if(!isVal){
		alert("输入内容的格式不正确");
		return false;
	}*/
	//if(isVal){
	if(isValAnd && isValOr && isValNot){
		//alert("验证正确");
		var expression = query.value;
		if(method == "toList"){//到列表页面
			var parent = window.opener;
			parent.document.getElementById("advanceQueryExpression").value = expression;
			parent.document.getElementsByName("date")[0].value = document.getElementsByName("date")[0].value;
			parent.document.getElementsByName("position")[0].value = document.getElementsByName("position")[0].value;
			parent.document.getElementsByName("pageSize")[0].value = document.getElementsByName("pageSize")[0].value;
			parent.document.forms[0].submit();
			window.close();
		}else{//到搜索结果页面
			document.getElementById("advanceQueryExpression").value = expression;
			form.submit();
		}
	}
	
}

submitForm = false;
function doSubmitForm(frm){
	/*
	if(frm["noField-phrase-input"].value.length > 0)
		frm["noField-phrase"].value = quote(frm["noField-phrase-input"].value);
	else if(frm["noField-phrase"].value.length > 0)
		frm["noField-phrase"].value = '';
	*/
	var query = doMakeQuery(frm.query);
	var expression = query.value;
	alert(expression);
}


</script>
